package com.hot100.mid;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 旋转图像,画图分析，先左右镜像， 在中心镜像(帮办法旋转上半部分或者下半部分)
 * @date 2022/8/7 15:10
 */
public class Demo15 {
    public static void main(String[] args) {
        // int[][] nums={{1,2,3},{4,5,6},{7,8,9}};
         int[][] nums={{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
       rotate(nums);

    }
    //通过画图分析，其实只需要先做个镜像，然后，交换i,j的值即可
    public static void rotate(int[][] matrix) {
        //镜像操作，及左右替换
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix.length/2; j++) {
                 int temp=matrix[i][j];
                 matrix[i][j]=matrix[i][matrix.length-1-j];
                 matrix[i][matrix.length-1-j]=temp;
            }
        }

        //交换i和j的值
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix.length; j++) {
                if(j>=matrix.length-i){
                         int temp=matrix[i][j];
                         matrix[i][j]=matrix[matrix.length-j-1][matrix.length-i-1];
                         matrix[matrix.length-j-1][matrix.length-i-1]=temp;
                }
            }
        }

    }
}
